﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data;
using Microsoft.SharePoint;

namespace JM.JCY.SharePointComponent.Survey.ViewAllSurvey
{
    public partial class ViewAllSurveyUserControl : UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("Title");
            dt.Columns.Add("Link");
            dt.Columns.Add("Desc");
            dt.Columns.Add("Created");
            SPWeb web = SPContext.Current.Web;
            foreach (SPList list in web.Lists)
            {
                if (list.BaseType == SPBaseType.Survey)
                {
                    DataRow newRow = dt.NewRow();
                    newRow["Title"] = list.Title.ToString();
                    newRow["Link"] = list.DefaultViewUrl.ToString();
                    newRow["Desc"] = list.Description;
                    newRow["Created"] = list.Created;
                    dt.Rows.Add(newRow);
                }

            }


            dt.DefaultView.Sort = "Created Desc";
            this.gvBC.DataSource = dt.DefaultView;
            this.gvBC.DataBind();
        }

        protected void gvBC_DataBound(object sender, GridViewRowEventArgs e)
        {
            var drv = (DataRowView)e.Row.DataItem;
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Literal Link = (Literal)e.Row.Cells[0].FindControl("ltRedirect");
                Link.Text = "<img src='/_layouts/images/itsurvey.png'>&nbsp;&nbsp;<a href='" + drv["Link"].ToString() + "'>" + drv["Title"].ToString() + "</a>";

                Literal Desc = (Literal)e.Row.Cells[0].FindControl("ltDesc");
                Desc.Text = drv["Desc"].ToString();
            
            }

        }

        //protected void lbCreateSurvey_Click(object sender, EventArgs e)
        //{
        //    Response.Redirect("CreateSurvey.aspx");
        //}
    }
}
